<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  #div1 {
    width: 200px;
    height: 200px;
    background: red;
    position: absolute;
  }
</style>
<script>
  window.onload = function () {

  }

  document.onmousemove = function (event) {
    let div1 = document.getElementById("div1")
    // div1.style.left = event.clientX - div1.offsetWidth / 2 +  "px"
    // div1.style.top = event.clientY + document.documentElement.scrollTop - div1.offsetHeight / 2 + "px"
    div1.style.left = event.pageX - div1.offsetWidth / 2 + "px"
    div1.style.top = event.pageY - div1.offsetHeight / 2 + "px"
  }
</script>

<body style="height: 1000px;">

  <div id="div1"></div>

</body>

</html>